<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Common;
use App\Http\Controllers\Data;
use App\Http\Controllers\SuccessCode;
use App\Model\ChannelLevel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class Channel extends Controller
{
    use Common;
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $list = \App\Model\Channel::all();

        foreach ($list as $key => $value) {
            $list[$key]->one = $value->one_channel;
            $list[$key]->two = $value->two_channel;
            $list[$key]->one_channel = $value->one_channel ?  ChannelLevel::find($value->one_channel)->name : '';
            $list[$key]->two_channel = $value->two_channel ?  ChannelLevel::find($value->two_channel)->name : '';
        }

        $tree = Data::getTree(ChannelLevel::all()->toArray(),'name');

        $arr = [
            'list' => $list,
            'tree' => $tree
        ];

        return $this->getView($arr,SuccessCode::GET_SUCCESS);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
